(function(angular){
	'use strict';
	angular.module('fs.waf').controller('cda.country.viewController',viewController);
	viewController.$inject = ['$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'countryService'];
	function viewController ($scope, Constants, layoutConfig, validatorConfig, gridService, authService, countryService){
		var ctrl = this, countryInfo = $scope.$stateParams.params;
		
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.init = function (){
			var params = {
				countryCode : countryInfo.countryCode
			};
			ctrl.innerGridOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.countryState.tableConfigs.table);
			ctrl.innerGridOptions.data = 'vm.country.states';
			ctrl.innerGridOptions.enableRowHeaderSelection = false;
			ctrl.defaultGridOptions = gridService.createGridOptions($scope, ctrl.layoutConfig.formConfigs.general);
			ctrl.defaultGridOptions.columnDefs = [];
			
			angular.merge(ctrl.defaultGridOptions.columnDefs,ctrl.layoutConfig.gridConfig);
			return authService.view(params).then(function(response){
				ctrl.country = response.data || countryInfo;
				ctrl.country.states = ctrl.country.states || [];
				angular.forEach(ctrl.country.states, function (con, key){
					if (con.dataStatus == 'V' || con.dataStatus == null) {
						con.dataStatus = 'V';
					} else {
						con.dataStatus = ctrl.country.dataStatus;
					}
				});
				
			},angular.noop());
		};		
	}	
})(angular);